package com.ruoyi.project.instrument.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;

import java.util.List;
import java.util.Arrays;

import com.ruoyi.common.utils.StringUtils;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.instrument.domain.InsOperationRecord;
import com.ruoyi.project.instrument.service.IInsOperationRecordService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 仪器操作记录Controller
 *
 * @author taney
 * @date 2020-06-08
 */
@AllArgsConstructor
@RestController
@RequestMapping("/instrument/operationRecord" )
public class InsOperationRecordController extends BaseController {

    private final IInsOperationRecordService iInsOperationRecordService;

    /**
     * 查询仪器操作记录列表
     */
    @PreAuthorize("@ss.hasPermi('instrument:operationRecord:list')")
    @GetMapping("/list")
    public TableDataInfo list(InsOperationRecord insOperationRecord)
    {
        startPage();
        LambdaQueryWrapper<InsOperationRecord> lqw = new LambdaQueryWrapper<InsOperationRecord>();
        if (insOperationRecord.getRecordTime() != null){
            lqw.eq(InsOperationRecord::getRecordTime ,insOperationRecord.getRecordTime());
        }
        if (StringUtils.isNotBlank(insOperationRecord.getChinesename())){
            lqw.like(InsOperationRecord::getChinesename ,insOperationRecord.getChinesename());
        }
        if (StringUtils.isNotBlank(insOperationRecord.getAction())){
            lqw.eq(InsOperationRecord::getAction ,insOperationRecord.getAction());
        }
        if (StringUtils.isNotBlank(insOperationRecord.getOldRecord())){
            lqw.eq(InsOperationRecord::getOldRecord ,insOperationRecord.getOldRecord());
        }
        if (StringUtils.isNotBlank(insOperationRecord.getNewRecord())){
            lqw.eq(InsOperationRecord::getNewRecord ,insOperationRecord.getNewRecord());
        }
        List<InsOperationRecord> list = iInsOperationRecordService.list(lqw);
        return getDataTable(list);
    }

    /**
     * 导出仪器操作记录列表
     */
    @PreAuthorize("@ss.hasPermi('instrument:operationRecord:export')" )
    @Log(title = "仪器操作记录" , businessType = BusinessType.EXPORT)
    @GetMapping("/export" )
    public AjaxResult export(InsOperationRecord insOperationRecord) {
        LambdaQueryWrapper<InsOperationRecord> lqw = new LambdaQueryWrapper<InsOperationRecord>(insOperationRecord);
        List<InsOperationRecord> list = iInsOperationRecordService.list(lqw);
        ExcelUtil<InsOperationRecord> util = new ExcelUtil<InsOperationRecord>(InsOperationRecord. class);
        return util.exportExcel(list, "operationRecord" );
    }

    /**
     * 获取仪器操作记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('instrument:operationRecord:query')" )
    @GetMapping(value = "/{id}" )
    public AjaxResult getInfo(@PathVariable("id" ) Long id) {
        return AjaxResult.success(iInsOperationRecordService.getById(id));
    }

    /**
     * 新增仪器操作记录
     */
    @PreAuthorize("@ss.hasPermi('instrument:operationRecord:add')" )
    @Log(title = "仪器操作记录" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody InsOperationRecord insOperationRecord) {
        return toAjax(iInsOperationRecordService.save(insOperationRecord) ? 1 : 0);
    }

    /**
     * 修改仪器操作记录
     */
    @PreAuthorize("@ss.hasPermi('instrument:operationRecord:edit')" )
    @Log(title = "仪器操作记录" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody InsOperationRecord insOperationRecord) {
        return toAjax(iInsOperationRecordService.updateById(insOperationRecord) ? 1 : 0);
    }

    /**
     * 删除仪器操作记录
     */
    @PreAuthorize("@ss.hasPermi('instrument:operationRecord:remove')" )
    @Log(title = "仪器操作记录" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}" )
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(iInsOperationRecordService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
